package flc.ast.dialog;

import static com.blankj.utilcode.util.StringUtils.getString;

import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;

import flc.ast.R;
import flc.ast.databinding.DialogInputAnswerBinding;
import flc.ast.databinding.DialogSetAnswerBinding;
import flc.ast.utils.Content;
import stark.common.basic.base.BaseSmartDialog;
import stark.common.basic.utils.SPUtil;

public class InputAnswerDialog extends BaseSmartDialog<DialogInputAnswerBinding> implements View.OnClickListener {


    public InputAnswerDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }

    @Override
    protected boolean canceledOnTouchOutside() {
        return true;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_input_answer;
    }

    @Override
    protected void initView(View view) {
        //密保设置
        mDataBinding.tvDialogInputAnswerConfirm.setOnClickListener(this);
        String spProblem = SPUtil.getString(getContext(), Content.myProblem, "");
        //密保问题
        mDataBinding.tvDialogInputAnswerQuestion.setText(spProblem);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tvDialogInputAnswerConfirm://完成设置
                String answer = mDataBinding.etDialogInputAnswerAnswer.getText().toString();
                if (TextUtils.isEmpty(answer)) {
                    ToastUtils.showShort(getString(R.string.please_input_answer));
                    return;
                }
                String spAnswer = SPUtil.getString(getContext(), Content.myAnswer, "");
                if (answer.equals(spAnswer)) {
                    //进入设置密码布局
                    dismiss();
                    listener.changePassword();
                } else {
                    mDataBinding.etDialogInputAnswerAnswer.setText("");
                    ToastUtils.showShort(R.string.answer_input_error);
                }
                break;
        }
    }


    private Listener listener;

    public void setListener(Listener listener) {
        this.listener = listener;
    }

    public interface Listener {
        void changePassword();
    }
}
